import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:healthy_station_flutter/utils/app_utils.dart';
import 'package:healthy_station_flutter/utils/res_images.dart';
import 'package:provider/provider.dart';

import '../../provider/provider_login.dart';
import '../../utils/constants.dart';
import '../../utils/res_colors.dart';
import '../../utils/res_strings.dart';
import '../../utils/screen_adapter.dart';
import '../../widget/sound_dialog.dart';

/// 
/// @Description 
/// @Author WuJianFeng
/// @Date 2024/3/1 17:55
/// 

class LoginBottomWidget extends StatefulWidget{
  const LoginBottomWidget({super.key});

  @override
  State<StatefulWidget> createState() => _LoginBottomWidgetState();
  
}

class _LoginBottomWidgetState extends State<LoginBottomWidget>{

  var showSoundWidget = false.obs;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: Adapt.pt(40)),
      child: Consumer<LoginProvider>(builder: (context, LoginProvider loginProvider, child) {

        return Stack(
          children: [
            ///帮助
            Positioned(
              child: Align(
                alignment: Alignment.bottomLeft,
                child: Container(
                  margin: EdgeInsets.only(left: (loginProvider.loginType != loginTypeInit? Adapt.pt(81) : Adapt.pt(147))),
                  child: InkWell(
                      onTap: () {
                        showDialog(
                          context: context,
                          builder: (BuildContext context) {
                            return Dialog(
                              //背景透明
                              backgroundColor: Colors.transparent,
                              // 设置内边距为零
                              insetPadding: EdgeInsets.zero,
                              child: Container(
                                width: Adapt.pt(1261),
                                height: Adapt.pt(926),
                                child: Stack(
                                  children: [
                                    Positioned.fill(
                                      child: Align(
                                        child: ImageUtils.getImgWithSize("icon_help_home.webp", 1261, 926),
                                      ),
                                    ),
                                    Positioned(
                                      top: Adapt.pt(150),
                                      left: Adapt.pt(550),
                                      child: Align(
                                        alignment: Alignment.topLeft,
                                        child: RichText(
                                          text: TextSpan(
                                              text: "设备名称  ",
                                              style: TextStyle(fontSize: Adapt.pt(28), color: Colors.black),
                                              children: [
                                                TextSpan(
                                                    text: "智慧健康站",
                                                    style: TextStyle(
                                                        fontSize: Adapt.pt(28),
                                                        color: color_0b8fee))
                                              ]
                                          ),
                                        ),
                                      ),
                                    ),
                                    Positioned(
                                      top: Adapt.pt(208),
                                      left: Adapt.pt(550),
                                      child: Align(
                                        alignment: Alignment.topLeft,
                                        child:FutureBuilder(
                                            future: AppUtils.getVersion(),
                                            builder: (context, AsyncSnapshot<String> snapshot) {
                                              return RichText(
                                                text: TextSpan(
                                                    text: "软件版本  ",
                                                    style: TextStyle(fontSize: Adapt.pt(28), color: Colors.black),
                                                    children: [
                                                      TextSpan(
                                                          text: snapshot.data,
                                                          style: TextStyle(
                                                              fontSize: Adapt.pt(28),
                                                              color: color_0b8fee))
                                                    ]
                                                ),
                                              );
                                            })
                                        ,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            );
                          },
                        );

                      },
                      child:LoginBottomItem("login_bottom_help.webp",sHelp)
                  ),
                ),
              ),
            ),
            ///音量
            Positioned(
              child: Align(
                alignment: (loginProvider.loginType != loginTypeInit)? Alignment.bottomCenter:Alignment.bottomRight,
                child: Container(
                  margin: EdgeInsets.only(right: (loginProvider.loginType != loginTypeInit? 0 : Adapt.pt(147))),
                  child: InkWell(
                  onTap: (){
                    showSoundWidget.value = !showSoundWidget.value;
                  },
                  child:LoginBottomItem("login_bottom_sound.webp",sSound),
                ),
                ),
              ),
            ),
            ///切换登录方式
            Visibility(
                visible: (loginProvider.loginType != loginTypeInit && loginProvider.loginType != loginTypeSuccess),
                child: Positioned(
                  child: Align(
                    alignment: Alignment.bottomRight,
                    child: Container(
                      margin: EdgeInsets.only(right: Adapt.pt(41)),
                      child: InkWell(
                          onTap: (){
                            loginProvider.setLoginType(loginTypeInit);
                          },
                          child:LoginBottomItem("login_bottom_trans.webp",sTrans),
                      ),
                    ),
                  ),
                )
            ),
            ///返回首页
            Visibility(
                visible: loginProvider.loginType == loginTypeSuccess,
                child: Positioned(
                  child: Align(
                    alignment: Alignment.bottomRight,
                    child: Container(
                      margin: EdgeInsets.only(right: Adapt.pt(81)),
                      child: InkWell(
                          onTap: (){
                            Fluttertoast.showToast(msg: "当前已是首页");
                          },
                          child:LoginBottomItem("login_bottom_home.webp",sHome),
                      ),
                    ),
                  ),
                )
            ),
            ///音量弹窗
            Positioned(
              child: Align(
                alignment: Alignment.bottomRight,
                child: Obx((){
                  return Visibility(
                      visible: showSoundWidget.value,
                      child: Container(
                        margin: EdgeInsets.only(bottom:Adapt.pt(140), right: (loginProvider.loginType != loginTypeInit? Adapt.pt(241 - 62) : Adapt.pt(147 - 62))),
                        child: SoundDialog(),
                      )
                  );
                }),
              ),
            )

          ],
        );
      }),
    );
  }


  Widget LoginBottomItem(String imgName, String content, {int marginLeft = 0, int marginRight = 0}){
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          margin: EdgeInsets.only(bottom: Adapt.pt(16)),
          width: Adapt.pt(88),
          height: Adapt.pt(88),
          child: ImageUtils.getImg(imgName),
        ),
        Text(content,style: TextStyle(fontSize: Adapt.pt(28), color: Colors.white))
      ],
    );
  }
  
}
 
 